home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / Make / source / vmsfunctions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-26  |  5.5 KB  |  236 lines

  1. #define KDEBUG 0
  2. /* vmsfunctions.c */
  3.  
  4. #include <stdio.h>
  5. #include "make.h"
  6. #ifdef __DECC
  7. #include <starlet.h>
  8. #endif
  9. #include <descrip.h>
  10. #include <rms.h>
  11. #include <iodef.h>
  12. #include <atrdef.h>
  13. #include <fibdef.h>
  14. #include "vmsdir.h"
  15.  
  16. DIR *opendir(char *dspec)
  17. {
  18.   static struct FAB *dfab;
  19.   struct NAM *dnam;
  20.   char *searchspec;
  21.  
  22.   if ((dfab = (struct FAB *)xmalloc(sizeof (struct FAB))) == NULL) {
  23.     printf("Error mallocing for FAB\n");
  24.     return(NULL);
  25.   }
  26.   if ((dnam = (struct NAM *)xmalloc(sizeof (struct NAM))) == NULL) {
  27.     printf("Error mallocing for NAM\n");
  28.     free(dfab);
  29.     return(NULL);
  30.   }
  31.   if ((searchspec = (char *)xmalloc(MAXNAMLEN+1)) == NULL) {
  32.     printf("Error mallocing for searchspec\n");
  33.     free(dfab);
  34.     free(dnam);
  35.     return(NULL);
  36.   }
  37.  
  38.   sprintf(searchspec,"%s*.*;",dspec);
  39.  
  40.   *dfab = cc$rms_fab;
  41.   dfab->fab$l_fna = searchspec;
  42.   dfab->fab$b_fns = strlen(searchspec);
  43.   dfab->fab$l_nam = dnam;
  44.  
  45.   *dnam = cc$rms_nam;
  46.   dnam->nam$l_esa = searchspec;
  47.   dnam->nam$b_ess = MAXNAMLEN;
  48.  
  49.   if (!(sys$parse(dfab) & 1)) {
  50.     free(dfab);
  51.     free(dnam);
  52.     free(searchspec);
  53.     return(NULL);
  54.   }
  55.  
  56.   return(dfab);
  57. }
  58.  
  59. #include <ctype.h>
  60. #define uppercasify(str) { char *tmp; for(tmp = (str); *tmp != '\0'; tmp++) if(islower(*tmp)) *tmp = toupper(*tmp); }
  61.  
  62. struct direct *readdir(DIR *dfd)
  63. {
  64.   static struct direct *dentry;
  65.   static char resultspec[MAXNAMLEN+1];
  66.   int i;
  67.  
  68.   if ((dentry = (struct direct *)xmalloc(sizeof (struct direct))) == NULL) {
  69.     printf("Error mallocing for direct\n");
  70.     return(NULL);
  71.   }
  72.  
  73.   dfd->fab$l_nam->nam$l_rsa = resultspec;
  74.   dfd->fab$l_nam->nam$b_rss = MAXNAMLEN;
  75.  
  76.   if (debug_flag)
  77.     printf(".");
  78.  
  79.   if (!((i = sys$search(dfd)) & 1)) {
  80.     if (debug_flag)
  81.       printf("sys$search failed with %d\n", i);
  82.     free(dentry);
  83.     return(NULL);
  84.   }
  85.  
  86.   dentry->d_off = 0;
  87.   if (dfd->fab$l_nam->nam$w_fid == 0)
  88.     dentry->d_fileno = 1;
  89.   else dentry->d_fileno = dfd->fab$l_nam->nam$w_fid[0]
  90.              +dfd->fab$l_nam->nam$w_fid[1]<<16;
  91.   dentry->d_reclen = sizeof (struct direct);
  92. /*
  93.   if (!strcmp(dfd->fab$l_nam->nam$l_type,".DIR"))
  94.     dentry->d_namlen = dfd->fab$l_nam->nam$b_name;
  95.   else
  96. */
  97.     dentry->d_namlen = dfd->fab$l_nam->nam$b_name+dfd->fab$l_nam->nam$b_type;
  98.   strncpy(dentry->d_name,dfd->fab$l_nam->nam$l_name,dentry->d_namlen);
  99.   dentry->d_name[dentry->d_namlen] = '\0';
  100.   uppercasify(dentry->d_name);
  101. /*  uvUnFixRCSSeparator(dentry->d_name);*/
  102.  
  103.   return(dentry);
  104. }
  105.  
  106. closedir(DIR *dfd)
  107. {
  108.   if (dfd != NULL) {
  109.     if (dfd->fab$l_nam != NULL)
  110.       free(dfd->fab$l_nam->nam$l_esa);
  111.     free(dfd->fab$l_nam);
  112.     free(dfd);
  113.   }
  114. }
  115.  
  116. char *getwd(char *cwd)
  117. {
  118.   static char buf[512];
  119.  
  120.     if (cwd)
  121.       return(getcwd(cwd,512));
  122.     else
  123.       return(getcwd(buf,512));
  124. }
  125.  
  126. int
  127. vms_stat (name, buf)
  128.      char *name;
  129.      struct stat *buf;
  130. {
  131.   int status;
  132.   int i;
  133.  
  134.   static struct FAB Fab;
  135.   static struct NAM Nam;
  136.   static struct fibdef Fib; /* short fib */
  137.   static struct dsc$descriptor FibDesc =
  138.     {sizeof(Fib), DSC$K_DTYPE_Z, DSC$K_CLASS_S, (char *)&Fib};
  139.   static struct dsc$descriptor_s DevDesc =
  140.     {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, &Nam.nam$t_dvi[1]};
  141.   static char EName[NAM$C_MAXRSS];
  142.   static char RName[NAM$C_MAXRSS];
  143.   static struct dsc$descriptor_s FileName =
  144.     {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
  145.   static struct dsc$descriptor_s string =
  146.     {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};  
  147.   static unsigned long Rdate[2];
  148.   static unsigned long Cdate[2];
  149.   static struct atrdef Atr[] = {  
  150.     {sizeof(Rdate),ATR$C_REVDATE,&Rdate[0]}, /* Revision date */
  151.     {sizeof(Cdate),ATR$C_CREDATE,&Cdate[0]}, /* Creation date */
  152.     {0,0,0}
  153.   };
  154.   static short int DevChan;
  155.   static short int iosb[4];
  156.  
  157.   name = vmsify (name, 0);
  158.  
  159.   /* initialize RMS structures, we need a NAM to retrieve the FID */
  160.   Fab = cc$rms_fab;
  161.   Fab.fab$l_fna = name ; /* name of file */
  162.   Fab.fab$b_fns = strlen(name);
  163.   Fab.fab$l_nam = &Nam; /* FAB has an associated NAM */
  164.       
  165.   Nam = cc$rms_nam;
  166.   Nam.nam$l_esa = EName; /* expanded filename */
  167.   Nam.nam$b_ess = sizeof(EName);
  168.   Nam.nam$l_rsa = RName; /* resultant filename */
  169.   Nam.nam$b_rss = sizeof(RName);
  170.  
  171.   /* do $PARSE and $SEARCH here */
  172.   status = sys$parse(&Fab);
  173.   if (!(status & 1))
  174.     return -1;
  175.  
  176.   DevDesc.dsc$w_length = Nam.nam$t_dvi[0];
  177.   status = sys$assign(&DevDesc,&DevChan,0,0);
  178.   if (!(status & 1))
  179.     return -1;
  180.  
  181.   FileName.dsc$a_pointer = Nam.nam$l_name;
  182.   FileName.dsc$w_length = Nam.nam$b_name+Nam.nam$b_type+Nam.nam$b_ver;
  183.   
  184.   /* Initialize the FIB */
  185.   for (i=0;i<3;i++)
  186.     {
  187. #if __DECC
  188.       Fib.fib$w_fid[i]=Nam.nam$w_fid[i];
  189.       Fib.fib$w_did[i]=Nam.nam$w_did[i];
  190. #else
  191.       Fib.fib$r_fid_overlay.fib$w_fid[i]=Nam.nam$w_fid[i];
  192.       Fib.fib$r_did_overlay.fib$w_did[i]=Nam.nam$w_did[i];
  193. #endif
  194.     }
  195.  
  196.   status = sys$qiow(0,DevChan,IO$_ACCESS,&iosb,0,0,
  197.                         &FibDesc,&FileName,0,0,&Atr,0);
  198.   sys$dassgn (DevChan);
  199.   if (!(status & 1))
  200.     return -1;
  201.   status = iosb[0];
  202.   if (!(status & 1))
  203.     return -1;
  204.  
  205.   status = stat (name, buf);
  206.   if (status)
  207.     return -1;
  208.  
  209.   buf->st_mtime = ((Rdate[0]>>24) & 0xff) + ((Rdate[1]<<8) & 0xffffff00);
  210.   buf->st_ctime = ((Cdate[0]>>24) & 0xff) + ((Cdate[1]<<8) & 0xffffff00);
  211.   return 0;
  212. }
  213.  
  214. char *
  215. cvt_time(tval)
  216.   unsigned long tval;
  217. {
  218.   static long int date[2];
  219.   static char str[27];
  220.   static struct dsc$descriptor date_str =
  221.     {26, DSC$K_DTYPE_T, DSC$K_CLASS_S, str};
  222.  
  223.   date[0] = (tval & 0xff) << 24;
  224.   date[1] = ((tval>>8) & 0xffffff);
  225.  
  226.   if ((date[0]==0) && (date[1]==0))
  227.     return("never");
  228.  
  229.   sys$asctim(0,&date_str,date,0);
  230.   str[26]='\0';
  231.  
  232.   return(str);
  233. }
  234.   
  235. /* EOF */
  236.